package com.example.speeddating.controller;

import com.example.speeddating.common.BaseResponse;
import com.example.speeddating.common.RespGenerator;
import com.example.speeddating.entity.ArticleImage;
import com.example.speeddating.entity.TokenEntity;
import com.example.speeddating.annotaion.LoginUser;
import com.example.speeddating.annotaion.TokenCheck;
import com.example.speeddating.service.ArticleImageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 *
 * @author tina
 * @since 2023-06-28 11:14:33
 */
@Slf4j
@RestController
@RequestMapping("/articleImage")
public class ArticleImageController {

    @Value("${soulmate.serverPath}"+"image/")
    private String path;

    @Autowired
    private ArticleImageService articleImageService;

    @TokenCheck(roles = "user")
    @PostMapping
    public BaseResponse addArticleImage(@LoginUser TokenEntity tokenEntity,@RequestBody HashMap<String,Object> jsonString){
        log.info(jsonString.toString());
        ArticleImage articleImage = new ArticleImage();
        articleImage.setImage1(jsonString.get("image1")==null?null:jsonString.get("image1").toString());
        articleImage.setImage2(jsonString.get("image2")==null?null:jsonString.get("image2").toString());
        articleImage.setImage3(jsonString.get("image3")==null?null:jsonString.get("image3").toString());
        articleImage.setImage4(jsonString.get("image4")==null?null:jsonString.get("image4").toString());
        articleImage.setImage5(jsonString.get("image5")==null?null:jsonString.get("image5").toString());
        articleImage.setImage6(jsonString.get("image6")==null?null:jsonString.get("image6").toString());
        articleImage.setArticleId(Long.valueOf((jsonString.get("articleId").toString())));
        articleImageService.save(articleImage);
        return RespGenerator.returnOK("添加成功");
    }



}
